import * as CommonUtils from '../../utils/utils.js';
let userInfoDefault = ''

export let userInfo = (() => {
	let key = 'userInfo'+CommonUtils.getVersionCode();
	return new Promise(async (resolve, reject) => {
		let data = await uni.getStorageSync(key)
		if (data === '') {
			uni.setStorageSync(key, userInfoDefault)
			resolve(userInfoDefault)
		} else {
			resolve(data)
		}
	})
})()

let tokenDefault = ''
export let token = (() => {
	let key = 'token' + CommonUtils.getVersionCode();
	return new Promise(async (resolve, reject) => {
		let data = await uni.getStorageSync(key)
		if (data === '') {
			uni.setStorageSync(key, tokenDefault)
			resolve(tokenDefault)
		} else {
			resolve(data)
		}
	})
})()

let tallysDefault = []
export let tallys = (() => {
	let key = 'tallys' + CommonUtils.getVersionCode();
	return new Promise(async (resolve, reject) => {
		let data = await uni.getStorageSync(key)
		if (data === '') {
			uni.setStorageSync(key, tallysDefault)
			resolve(tallysDefault)
		} else {
			resolve(data)
		}
	})
})()


let tallyDefault = {
	id:'',
	title:''
}
export let tally = (() => {
	let key = 'tally' + CommonUtils.getVersionCode();
	return new Promise(async (resolve, reject) => {
		let data = await uni.getStorageSync(key)
		console.log(data);
		if (data === '') {
			uni.setStorageSync(key, tallyDefault)
			resolve(tallyDefault)
		} else {
			resolve(data)
		}
	})
})()


